package com.dao.kind;

import com.enitiy.Kind;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * 创建作者 ：MySunshine
 * 创建时间 2022/10/24 16:41
 * 项目名称 SHUSHAN
 */
public class KindDaoImpl implements  KindDao {
    QueryRunner qr = new QueryRunner(new ComboPooledDataSource());
    @Override //小说类型查询
    public List<Kind> kindSelectAll() throws SQLException {
       String sql="select * from kind";
        return  qr.query(sql, new BeanListHandler<Kind>(Kind.class));
    }

    @Override//根据编号改名子
    public boolean kindUpdateKindById(int kid ,String kind) throws SQLException {
        String sql="update kind set kind=? where kid=? ";
        int update = qr.update(sql, kind, kid);
        return update>=1?true:false;
    }

    @Override //添加新类型
    public boolean kindAdd(String kind) throws SQLException {
        String sql="insert  into kind(kind) value(?) ";
        int update = qr.update(sql, kind);
        return update>=1?true:false;
    }
}
